﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyGym
{
    public partial class MyGymForm : Form
    {
        DateTime dtStartTime = DateTime.MinValue;
        int nCount = 0;
        int nNum = 0;
        bool bIsGyming = false;
        bool bIsStarting = false;

        public MyGymForm()
        {
            InitializeComponent();
        }



        private void MyGymForm_Load(object sender, EventArgs e)
        {
            
        }

        private void timerRefresh_Tick(object sender, EventArgs e)
        {
            if (!bIsStarting )
                return;

            if (dtStartTime == DateTime.MinValue && nCount > 10)
            {
                if (nNum > 5)
                    return;
                else
                {
                    nNum++;
                    nCount = 0;
                    dtStartTime = dtStartTime.AddSeconds(10);
                    bIsGyming = false;
                    this.labelTime.BackColor = Color.Yellow;
                }  
            }
            if (dtStartTime == DateTime.MinValue)
            {
                this.labelNum.Text = string.Format("第{0:D2}组", nNum + 1);
                this.labelCount.Text = string.Format("第{0:D2}个", nCount + 1 );
                if( bIsGyming )
                {
                    dtStartTime = dtStartTime.AddSeconds(3);
                    bIsGyming = false;
                    this.labelTime.BackColor = Color.Gray;
                    nCount++;
                }
                else
                {
                    dtStartTime = dtStartTime.AddSeconds(6);
                    bIsGyming = true;
                    this.labelTime.BackColor = Color.Green;
                }
            }

            Timer tm = sender as Timer;
            dtStartTime = dtStartTime.AddMilliseconds(-tm.Interval);
            if (checkBoxShowTime.Checked)
                this.labelTime.Text = string.Format("{0:D2}:{1:D2}:{2:D3}", dtStartTime.Minute, dtStartTime.Second, dtStartTime.Millisecond);
            else
                this.labelTime.Text = string.Empty;
        }

        private void buttonStart_Click(object sender, EventArgs e)
        {
            if (bIsStarting)
            {
                bIsStarting = false;
                this.buttonStart.Text = "Start";
            }
            else
            {
                bIsStarting = true;
                this.buttonStart.Text = "Stop";
            }
        }
    }
}
